package com.why.service.impl;

import com.why.common.utils.PageUtils;
import com.why.common.utils.Query;
import com.why.dao.ShoppingCartDao;
import com.why.entity.ShoppingCartEntity;
import com.why.service.ShoppingCartService;
import com.why.vo.ShoppingCartVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


@Service("shoppingCartService")
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartDao, ShoppingCartEntity> implements ShoppingCartService {

    @Autowired
    ShoppingCartDao shoppingCartDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ShoppingCartEntity> page = this.page(
                new Query<ShoppingCartEntity>().getPage(params),
                new QueryWrapper<ShoppingCartEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<ShoppingCartVO> getShoppingCartVOs(Long userId){
       return shoppingCartDao.selectShoppingCarts(userId);
    }

    @Override
    public int  updateCartnumByCartid(Long cartid, Long cartNum){
        return shoppingCartDao.updateCartnumByCartid(cartid,cartNum);
    }

    @Override
    public Collection<ShoppingCartEntity> getListByIds(Set<Long> userIds) {
        return shoppingCartDao.selectShopcartByCids(userIds);
    }

}